<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        * {
            margin: 0;
            padding: 0;
        }

        .goodWarmp {
            width: 500px;
            display: flex;
            justify-content: left;
            border: 1px dashed black;
        }

        .goodWarmp>div:last-child {
            text-align: left;
        }

        .detail {
            width: 200px;
            height: 200px;
            background-color: #cccccc;
            position: fixed;
            right: 10px;
            top: 100px;
            border: 2px solid black;
        }
    </style>
</head>

<body>
    <div id="app">
        <film-item v-for='item in dataList' :key='item.id' :mydata='item' @give-detail='getDetail'></film-item>
        <show-detail :detail='detail'></show-detail>
    </div>
    <script src="./js/vue.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"></script>
    <script>
        Vue.component('filmItem', {
            template: `
                <div class="goodWarmp">
                    <div>
                        <img :src="mydata.img" style='height: 140px;width:100px;'/>
                    </div>
                    <div>
                        <h2>{{mydata.nm}}</h2>
                        <p>
                            电影评分：<span>{{mydata.sc}}</span>
                        </p>
                        <p>
                            主要演员：<span>{{mydata.star}}</span>
                        </p>
                        <p>
                            <button @click="emitDetail">详情</button>
                        </p>
                    </div>
                </div>
            `,
            props: ['mydata'],
            data() {
                return {
                }
            },
            mounted() {
                this.mydata.img = this.mydata.img.split('/w.h').join('')
            },
            methods: {
                emitDetail() {
                    this.$emit('give-detail', this.mydata.showInfo)
                }
            }
        })
        //创建详情显示组件
        Vue.component("showDetail", {
            template: `
                <div class="detail">{{detail?detail:"请点击查看详情"}}</div>
            `,
            props: ['detail'],
            mounted() {

            },
            data() {
                return {

                }
            }
        })
        const vm = new Vue({
            el: '#app',
            data: {
                dataList: [],
                detail: ''
            },
            methods: {
                getDetail(detail) {
                    this.detail = detail
                }
            },
            mounted() {
                axios.get('./data.json').then(res => {
                    this.dataList = res.data.movieList
                })
            }
        })
    </script>

</body>

</html>